/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sisgea.controller;


import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import sisgea.bean.ExperimentoBean;
import sisgea.conexaobd.ConexaoBD;
import sisgea.conexaobd.ConexaoPost;


/**
 *
 * @author Usuario
 */
public class ExperimentoControl {
    
    PreparedStatement pstm;
    ResultSet rs;
    String consultaExperimento = "SELECT * FROM TBLEXPERIMENTO WHERE EXPERIMENTO LIKE ?";
    String cadastraExperimento = "INSERT INTO tblExperimentos (Empresa, TipoExperimento, Experimento, DescExperimento, Objetivos, TipoDelineamento, GrupoExperimento, CodigoVelho, Regiao, Fazenda, Talhao, DataPlantio, Area, AreaUtil, NumeroTratamentos, NumeroTestemunhos, NumeroBlocos, NumeroLinhas, Solo, UnidadeManejo, Status, DataDesativacao, Mensuravel, Cortado, NumeroArvoreParcelas, NumeroArvoreMedidas, NumeroPlantasOriginal, NumeroPlantasAtual, AdubacaoBase, DataAdubacaoBase, AdubacaoCobertura, DataAdubacaoCobertura, DataUltimaMedicao, InformarAltura, InformarCAP, AlturaMinima, AlturaMaxima, CAPMinima, CAPMaxima, IMAMaximoDeficiente, IMAMinimoAlto, RestringeUsuarios, LocalizacaoCroqui, Observacao, UsuarioQueIncluiu, DataInclusao, DataUltimaAtualizacao) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    
   
    public ExperimentoControl(){
    }
    
    public void cadastrarExperimento(ExperimentoBean experimento){
        
        try{
            ConexaoPost conexao = new ConexaoPost();
            pstm = (PreparedStatement) conexao.conectar().prepareStatement(cadastraExperimento);
            pstm.setString(1, experimento.getEmpresa());
            pstm.setString(2, experimento.getTipoexperimento());
            pstm.setString(3, experimento.getExperimento());
            pstm.setString(4, experimento.getDescexperimento());
            pstm.setString(5, experimento.getObjetivos());
            pstm.setString(6, experimento.getTipodelineamento());
            pstm.setString(7, experimento.getGrupoexperimento());
            pstm.setString(8, experimento.getCodigvelho());
            pstm.setString(9, experimento.getRegiao());
            pstm.setString(10, experimento.getFazenda());
            pstm.setString(11, experimento.getTalhao());
            pstm.setString(12, experimento.getDataplantio());
            pstm.setInt(13, experimento.getArea());
            pstm.setInt(14, experimento.getAreautil());
            pstm.setInt(15, experimento.getNumerotratamentos());
            pstm.setInt(16, experimento.getNumerotestemunhos());
            pstm.setInt(17, experimento.getNumeroblocos());
            pstm.setInt(18, experimento.getNumerolinhas());
            pstm.setString(19, experimento.getSolo());
            pstm.setString(20, experimento.getUnidademanejo());
            pstm.setString(21, experimento.getStatus());
            pstm.setString(22, experimento.getDatadesativacao());
            pstm.setString(23, experimento.getMensuravel());
            pstm.setString(24, experimento.getCortado());
            pstm.setInt(25, experimento.getNumeroarvoreparcelas());
            pstm.setInt(26, experimento.getNumeroarvoremedidas());
            pstm.setInt(27, experimento.getNumeroplantasoriginal());
            pstm.setInt(28, experimento.getNumeroplantasatual());
            pstm.setString(29, experimento.getAdubacaobase());
            pstm.setString(30, experimento.getDataadubacaobase());
            pstm.setString(31, experimento.getAdubacaocobertura());
            pstm.setString(32, experimento.getDataadubacaocobertura());
            pstm.setString(33, experimento.getDataultimamedicao());
            pstm.setString(34, experimento.getInformaraltura());
            pstm.setString(35, experimento.getInformarcap());
            pstm.setInt(36, experimento.getAlturaminima());
            pstm.setInt(37, experimento.getAlturamaxima());
            pstm.setInt(38, experimento.getCapminima());
            pstm.setInt(39, experimento.getCapmaxima());
            pstm.setInt(40, experimento.getImamaximodeficiente());
            pstm.setInt(41, experimento.getImaminimoalto());
            pstm.setString(42, experimento.getRestringeusuario());
            pstm.setString(43, experimento.getLocalizacaocroqui());
            pstm.setString(44, experimento.getObservacao());
            pstm.setString(45, experimento.getUsuarioqueincluiu());
            pstm.setString(46, experimento.getDatainclusao());
            pstm.setString(47, experimento.getDataultimaatualizacao());
            
            pstm.executeUpdate();
            
            conexao.desconectar();
            
        }
        
        
        catch (Exception e){
            e.printStackTrace();
        }
    }
    
    
    
    public List<ExperimentoBean> ListarExperimentos(String experimento){
        List<ExperimentoBean> experimentos = null;
    
        try{
            ConexaoPost conecxao = new ConexaoPost();
            pstm = (PreparedStatement) conecxao.conectar().prepareStatement(consultaExperimento);
            pstm.setString(1, experimento);
            rs = pstm.executeQuery();
            ExperimentoBean exp;
            while (rs.next()){
                exp = new ExperimentoBean();
                
               exp.setEmpresa(rs.getString("empresa"));
               exp.setTipoexperimento(rs.getString("tipoexperimento"));
               exp.setExperimento(rs.getString("experimento"));
               exp.setDescexperimento(rs.getString("descexperimento"));
               exp.setObjetivos(rs.getString("objetivos"));
               exp.setTipodelineamento(rs.getString("tipodelineamento"));
               exp.setGrupoexperimento(rs.getString("grupoexperimento"));
               exp.setCodigvelho(rs.getString("codigovelho"));
               exp.setRegiao(rs.getString("regiao"));
               exp.setFazenda(rs.getString("fazenda"));
               exp.setDataplantio(rs.getString("dataplantio"));
               exp.setArea(rs.getInt("area"));
               exp.setAreautil(rs.getInt("areautil"));
               exp.setNumerotratamentos(rs.getInt("numerotratamento"));
               exp.setNumerotestemunhos(rs.getInt("numerotratamentos"));
               exp.setNumeroblocos(rs.getInt("numeroblocos"));
               exp.setNumerolinhas(rs.getInt("numerolinhas"));
               exp.setSolo(rs.getString("solo"));
               exp.setUnidademanejo(rs.getString("unidademanejo"));
               exp.setStatus(rs.getString("status"));
               exp.setDatadesativacao(rs.getString("dadadesativacao"));
               exp.setMensuravel(rs.getString("mensuravel"));
               exp.setCortado(rs.getString("cortado"));
               exp.setNumeroarvoreparcelas(rs.getInt("numeroarvoreparcelas"));
               exp.setNumeroarvoremedidas(rs.getInt("numeroarvoremedidas"));
               exp.setNumeroplantasoriginal(rs.getInt("numeroplantasoriginal"));
               exp.setNumeroplantasatual(rs.getInt("numeroplantasatual"));
               exp.setAdubacaobase(rs.getString("adubacaobase"));
               exp.setDataadubacaobase(rs.getString("dataadubacaobase"));
               exp.setAdubacaocobertura(rs.getString("adubacaocobertura"));
               exp.setDataadubacaocobertura(rs.getString("ataadubacaocobertura"));
               exp.setDataultimamedicao(rs.getString("dataultimamedicao"));
               exp.setInformaraltura(rs.getString("informaraltura"));
               exp.setInformarcap(rs.getString("informaraltura"));
               exp.setAlturaminima(rs.getInt("alturaminima"));
               exp.setAlturamaxima(rs.getInt("alturamaxima"));
               exp.setCapminima(rs.getInt("capminima"));
               exp.setCapmaxima(rs.getInt("capmaxima"));
               exp.setImamaximodeficiente(rs.getInt("imamaximodeficiente"));
               exp.setImaminimoalto(rs.getInt("imaminimoalto"));
               exp.setRestringeusuario(rs.getString("restringeusuario"));
               exp.setLocalizacaocroqui(rs.getString("localizacaocriqui"));
               exp.setObservacao(rs.getString("observacao"));
               exp.setUsuarioqueincluiu(rs.getString("usuarioqueincluiu"));
               exp.setDatainclusao(rs.getString("datainclusao"));
               exp.setDataultimaatualizacao(rs.getString("dataultimaatualizacao"));
               
               experimentos.add(exp);
               
            }
            
            conecxao.desconectar();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return experimentos;
        
    }
}
